package org.vectrics.recruiter.struts.tag;

/**
 * @author Mike Moore
 * @version 1.0
 */

import org.apache.log4j.Category;
import org.vectrics.common.html.Cell;
import org.vectrics.common.html.Row;
import org.vectrics.common.html.Table;
import org.vectrics.hibernate.ThreadProperties;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.skill.UserEvaluation;
import org.vectrics.struts.VectricsTagSupport;
import org.vectrics.user.Person;


public class MemberOptionsTag extends VectricsTagSupport {
	public static final long serialVersionUID = 2342355;
    static private Category log = Category.getInstance(MemberOptionsTag.class);
    
	public String makeStartTag() {
		StringBuffer content = new StringBuffer();
		log.debug("doStartTag() - called");
		try {
			Person user = this.getAuthPerson();
			if (user == null) {
				content.append("<font class=\"memberHeader\">" +
						this.getPhrase("heading.public.membership") +
						"<br></font>");
				content.append("<font class=\"anchorSpacer\">&nbsp;<br></font>");
				content.append("<font class=\"memberText\">" +
						this.getPhrase("phrase.membership.registration") +
						"<br></font>");
				content.append("<font class=\"anchorSpacer\">&nbsp;<br></font>");
				content.append("<br><a class=\"memberLink\" href=\"/hrs-public/public/" 
						+ ThreadProperties.getUriDomainId() + "/new_user.do?new=true&showUserName=y\">" +
								this.getPhrase("phrase.new.member") +
								"</a>");
				
				String loginForm = 
					"<form action=\"/hrs-public/public/" +  ThreadProperties.getUriDomainId()  + "/profile/summary.do\">"
					+ "  <input type=\"hidden\" name=\"domainId\" value=\"" + ThreadProperties.getDomain().getId() + "\"/>"
					
					+ "  <input type=\"hidden\" name=\"login\" value=\"true\">"
					+ "  <table cellpadding=\"1\" cellspacing=\"0\">"
							+ "<tr>"
							+ "<td valign=\"top\">"
								+ "<font class=\"mbrLoginCaption\">User</font><br>"
								+ "<input value=\"\" class=\"compactEditClass\" name=\"username\" type=\"text\"></td>"
							+ "</tr>"
							+ "<tr>"
							+ "<td valign=\"top\">"
								+ "<font class=\"mbrLoginCaption\">Password</font><br>"
								+ "<input value=\"\" class=\"compactEditClass\" name=\"password\" type=\"password\">"
								+ "</td>"
							+ "</tr>"
							+ "<tr>"
							+ "<td valign=\"TOP\" align=\"left\">"
								+ "<input name=\"submit\" type=\"submit\" value=\"Sign In\" class=\"formButton\">"
							+ "</td>"
							+ "</tr>"
					+ "    </table>"
				+ "</form>"
				
				+ "<script type=\"text/javascript\" language=\"JavaScript\">"
				+ "  <!--"
				+ "  var focusControl = document.forms[\"fm\"].elements[\"username\"];"
 			    + "if (focusControl.type != \"hidden\") {"
				+ "    focusControl.focus();"
				+ " }	  --></script>";
				
				
				content.append(loginForm);
			} else {
				
				content.append("<font class=\"memberWelcomeFont\">Welcome ");
				content.append(user.getFirstName() + " " + user.getLastName());
				content.append("!</font>");
				
				Table buttonTable = new Table();
				buttonTable.setCellPadding(3);

				
				Row row = buttonTable.addRow();
				Cell cell = row.addCell();
				cell.addElement("<br><a href=\"/hrs-public/public/" 
						+ ThreadProperties.getUriDomainId() + "/logoff.do" 
						+ "\"><img src=\"" +
				     		 this.getContextPath() + "/dynagraphic/button.jpg?code=job.apps.button&caption=" +
						this.getPhrase("button.logoff") + "\" border=\"0\" ></a>");				

				row = buttonTable.addRow();
				cell = row.addCell();
				UserEvaluation eval = RecruitServiceLocator.getSkillProvider().findLatestUserSelfEvaluation(user);
				String link = "<a href=\"/hrs-public/profile/" + ThreadProperties.getUriDomainId() + "/self_eval.do";
				if (eval != null) {
					link += "?evalId=" + eval.getId();
				}
				link += "\"><img src=\"" +
						 this.getContextPath() + "/dynagraphic/button.jpg?code=job.apps.button&caption=" +
						this.getPhrase("button.self.evaluation") + "\" border=\"0\" ></a>";
				cell.addElement(link);
				content.append(buttonTable.toString());
			}
			
	        
		}
		catch (Exception ex) {
			log.error("Exception writing MemberOptionsTag", ex);
		}
		
		return(content.toString());
    }

}
